package com.sc.basic.job;

import com.sc.basic.entity.City;
import com.sc.basic.service.CityDataService;
import com.sc.basic.service.WeatherDataService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.List;

/**
 * @author shuchang
 * @Date 2018/3/16 下午3:09
 */
@Slf4j
public class WeatherSyncJob extends QuartzJobBean{

    @Autowired
    private CityDataService cityDataService;
    @Autowired
    private WeatherDataService weatherDataService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        log.info("定时作业");
        List<City> cities = null;
        cities = cityDataService.listCity();
        cities.forEach(i->weatherDataService.syncDateByCityId(i.getCityId()));
        log.info("定时任务结束");
    }
}
